package com.agileboot.domain.performance.score.model;

import cn.hutool.core.bean.BeanUtil;
import com.agileboot.domain.performance.score.command.AddUserScoreRecordCommand;
import com.agileboot.domain.performance.score.command.UpdateUserScoreRecordCommand;
import com.agileboot.domain.performance.score.db.UserScoreRecordEntity;
import com.agileboot.domain.performance.score.db.UserScoreRecordService;
import lombok.NoArgsConstructor;

/**
 * 用户分数记录模型
 */
@NoArgsConstructor
public class UserScoreRecordModel extends UserScoreRecordEntity {

    private UserScoreRecordService userScoreRecordService;

    public UserScoreRecordModel(UserScoreRecordService userScoreRecordService) {
        this.userScoreRecordService = userScoreRecordService;
    }

    public UserScoreRecordModel(UserScoreRecordEntity entity, UserScoreRecordService userScoreRecordService) {
        if (entity != null) {
            BeanUtil.copyProperties(entity, this);
        }
        this.userScoreRecordService = userScoreRecordService;
    }

    public void loadFromAddCommand(AddUserScoreRecordCommand addCommand) {
        if (addCommand != null) {
            BeanUtil.copyProperties(addCommand, this, "id");
        }
    }

    public void loadFromUpdateCommand(UpdateUserScoreRecordCommand command) {
        if (command != null) {
            loadFromAddCommand(command);
        }
    }

    public void checkCanBeDeleted() {
        // 这里可以根据实际需求添加删除前的验证逻辑
    }

    public void checkUnique() {
        // 在此处添加您需要的唯一性验证（例如用户分数记录的特殊要求）
    }

}

